mn = input()
num_new = []
a = True
if len(mn) == 4:
    num = [mn[0], mn[1], mn[2], mn[3], mn[0] + mn[1], mn[1] + mn[2], mn[2] + mn[3], mn[0] + mn[1] + mn[2],mn[1] + mn[2] + mn[3], mn]
    for i in num:
        if int(i) == 1 or int(i) == 0:
            a = True
        else:
            for s in range(2, int(i) - 1):
                if int(i) % s == 0:
                    a = False
                    break
            if a:
                num_new.append(int(i))
            a = True

if num_new != []:
    print(max(num_new))
if num_new == [] or len(mn) != 4:
    print(0)